package com.EpidemicPrevention.controller;


import com.EpidemicPrevention.pojo.Help_info;
import com.EpidemicPrevention.service.Help_infoServiceIpml;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("/Help_infoController")
public class Help_infoController {

    @Autowired
    private Help_infoServiceIpml help_infoService;

    /*
     *添加用户
     * @Prama user 实体类
     * @return
     */
    @GetMapping("/addHelp_info")
    @ResponseBody
    @CrossOrigin
    public JSON addHelp_info(Help_info help_info) {
        return help_infoService.addHelp_info (help_info);
    }


    @GetMapping("/updataHelp_info")
    @ResponseBody
    @CrossOrigin
    public  JSON updataHelp_info(Help_info help_info){
        return help_infoService. updateHelp_info (help_info);
    }

    /**
     * 删除用户
     *
     * @param h_id
     * @return
     */
    @GetMapping("/deleteHelp_info")
    @ResponseBody
    @CrossOrigin
    public JSON deleteHelp_info(@RequestParam("h_id") int h_id) {
        return help_infoService.deleteHelp_info (h_id);
    }



    /**
     * 查看用户
     *
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/queryHelp_info")
    @ResponseBody
    @CrossOrigin
    public JSON queryHelp_info(@RequestParam("page") int page, @RequestParam("limit") int limit) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "");
        json.put("count",help_infoService.queryHelp_info (0, 100000,null).size());
        json.put("data", help_infoService.queryHelp_info (page2, limit,null));
        return json;
    }


    @GetMapping("/selectWhereHelp_info")
    @ResponseBody
    @CrossOrigin
    public JSON selectWhereHelp_info(@RequestParam("page")int page,@RequestParam("limit")int limit,@RequestParam("Keyword")String Keyword) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "查询成功");
        json.put("count", help_infoService.queryHelp_info (0, 100000, Keyword).size());
        json.put("data",help_infoService.queryHelp_info (page2, limit, Keyword));
        return json;
    }



}
